package com.x.crm.dao;


import com.x.crm.model.IntentionLevel;
import com.x.framework.dao.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class IntentionLevelDao extends BaseDao{


	private final static String baseSelectIntentionLevelListSql = "SELECT * FROM  CRM_INTENTION_LEVEL  I " +
			"WHERE 1=1 ";

	public List<IntentionLevel> selectIntentionLevelList(IntentionLevel intentionLevel) throws Exception {
		StringBuilder sb = new StringBuilder(baseSelectIntentionLevelListSql);
		List<Object> params = new ArrayList<Object>();
		searchBasicCondition(intentionLevel, sb, params);
		sb.append(" ORDER BY I.INTENTION_LEVEL_CREATE_TIME DESC");
		return this.queryForList(sb.toString(), IntentionLevel.class, params, intentionLevel);
	}


	private final static String baseSelectIntentionLevelNumSql = "SELECT COUNT(COOPERTYPE_ID) FROM  CRM_COOPERTYPE  I " +
			"WHERE 1=1 ";

	public int selectIntentionLevelNum(IntentionLevel intentionLevel) throws Exception {
		StringBuilder sb = new StringBuilder(baseSelectIntentionLevelNumSql);
		List<Object> params = new ArrayList<Object>();
		searchBasicCondition(intentionLevel, sb, params);
		return this.queryForInt(sb.toString(), params);
	}


	private void searchBasicCondition(IntentionLevel intentionLevel, StringBuilder sb, List<Object> params) {
		if (this.isString(intentionLevel.getIntentionLevelId())) {
			sb.append("AND I.INTENTION_LEVEL_ID = ? ");
			params.add(intentionLevel.getIntentionLevelId());
		}
	}


}
